<?php
	class TimeAndDate {

		# 요일명 반환
		public static function get_day_name_to_string($day){
			switch($day){
				case "0": $dayname = " 일";break;
				case "1": $dayname = " 월";break;
				case "2": $dayname = " 화";break;
				case "3": $dayname = " 수";break;
				case "4": $dayname = " 목";break;
				case "5": $dayname = " 금";break;
				case "6": $dayname = " 토";break;
			}
			return $dayname;
		}

		# 유닉스날짜 포맷
		public static function unixtime_to_date($unixtime, $format = "Y-m-d H:i:s", $empty = "&nbsp;") {
			if ($unixtime) return date($format, $unixtime);
			else return $empty;
		}

		# YYYY-MM-DD 형식을 유닉스 타임으로
		public static function time_to_unixtime($times, $operator = "-", $type = true) {
			if ($type == true) {
				$times = trim($times);
				$arry = explode($operator, $times);
				if (count($arry) != 3) return date_format(0);
				$mktime = mktime(0, 0, 0, $arry[1], $arry[2], $arry[0]);
				return date("U", $mktime);
			} else {
				$formats = "Y{$operator}m{$operator}d";
				return date($formats, $times);
			}
		}

		# 날짜 사이에 적용되는지 리턴
		public static function between_date($sdate,$edate) {
			$s = strtotime($sdate);
			$e = strtotime($edate);
			return ($e - $s) / (24*60*60);
		}

		# datetime -> timestamp
		public static function to_time_stamp($datetime){
			$y = substr($datetime,0,4);	$m = substr($datetime,5,2);	$d = substr($datetime,8,2);
			$h = substr($datetime,11,2);	$i = substr($datetime,14,2);	$s = substr($datetime,17,2);
			return mktime($h, $i, $s, $m, $d, $y);
		}


		# 주간 날짜 리턴
		# echo 'ytime>>'. $ytime . PHP_EOL;
		# echo 'ttime>>'. $ttime . PHP_EOL;
		public static function get_week_days() {
			if(!$time) $time = time();
			$week = date("w", $time);
			if(!$sunday) $sunday = mktime(0, 0, 0, date("m"), date("d") - $week, date("Y"));
			for ($L = 0, $day = $sunday; $L < 7; $L++, $day+= 86400) {
				echo date("Y-m-d (D)", $day) . PHP_EOL;
			}
			$ytime = $sunday - 604800;
			$ttime = $sunday + 604800;

			$ret = array();
			$ret['ytime'] = $ytime;
			$ret['ttime'] = $ttime;
			return $ret;
		}

	}
?>